/*
 *Copyright 2021-2023 NERCIS
 *
 *Licensed under the Apache License, Version 2.0 (the "License");
 *you may not use this file except in compliance with the License.
 *You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *Unless required by applicable law or agreed to in writing, software
 *distributed under the License is distributed on an "AS IS" BASIS,
 *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *See the License for the specific language governing permissions and
 *limitations under the License.
 */

package cn.ac.nercis.pes.common.constant.evaluation;

import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Objects;

/**
 * 密钥管理安全情况
 * @author zpy
 * @version 1.0.0
 */
public enum PwdRkCondition {
    /**默认，未填写**/
    DEFAULT(0,"",-1),
    /**使用二级密码模块**/
    TWO_LEVEL_MODULE(1,"二级密码模块",1.5f),
    /**一级密码模块**/
    ONE_LEVEL_MODULE(2,"一级密码模块",1.2f),
    /**其他情况**/
    OTHER_MODULE(3,"其他情况",1);

    private final int result;
    private final String name;
    private final float revise;

    PwdRkCondition(int result, String name, float revise) {
        this.result = result;
        this.name = name;
        this.revise = revise;
    }

    public static PwdRkCondition fromResult(Integer result){
        PwdRkCondition data = DEFAULT;
        for(PwdRkCondition tt : PwdRkCondition.values()){
            if(Objects.equals(tt.getResult(), result)){
                data = tt;
                break;
            }
        }
        return data;
    }

    public static PwdRkCondition fromName(String name){
        PwdRkCondition data = DEFAULT;
        for(PwdRkCondition tt : PwdRkCondition.values()){
            if(StringUtils.equals(tt.getName(),name)){
                data = tt;
                break;
            }
        }
        return data;
    }

    public static List<PwdRkCondition> findConditionsByThreeLevel(){
        return List.of(ONE_LEVEL_MODULE,OTHER_MODULE);
    }

    public static List<PwdRkCondition> findConditionsByFourLevel(){
        return List.of(TWO_LEVEL_MODULE,OTHER_MODULE);
    }

    public int getResult(){
        return this.result;
    }

    public String getName(){
        return this.name;
    }

    public float getRevise() {
        return revise;
    }
}
